package Admin;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dushibao.admin.AdminApplication;
import com.dushibao.admin.mapper.MenuMapper;
import com.dushibao.admin.model.Menu;
import com.dushibao.admin.service.IMenuService;

import com.dushibao.admin.vo.request.MenuModelPageRequest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  菜单 测试类
 *
 * @author zqd
 * @date 2021-12-07 08:28:35
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AdminApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MenuServiceDemo {

    @Autowired
    IMenuService menuService;

    @Autowired
    MenuMapper menuMapper;

    @Test
    public void findAdminMenuList(){
        List<Menu> menus = menuMapper.findAdminMenuList(2L);
        System.out.println(menus);
    }

    @Test
    public void findTreeMenu(){
        List<Menu> menus = menuMapper.findTreeMenu();
        System.out.println(menus);
    }

    @Test
    public void selectPages(){
        MenuModelPageRequest pageRequest = new MenuModelPageRequest();
        pageRequest.setCurrent(2);
        pageRequest.setPageSize(10);
        List<Menu> menus = menuMapper.selectPages(pageRequest);
        menus.forEach(System.out::println);

        int count = menuMapper.selectCount(pageRequest);

        System.out.println(count);
    }

    @Test
    public void selectTreeMenus(){
        MenuModelPageRequest pageRequest = new MenuModelPageRequest();
        pageRequest.setType("ADMIN");
        pageRequest.setId(21L);
        List<Menu> menus = menuMapper.selectTreeMenus(pageRequest);

        menus.forEach(System.out::println);

    }

    @Test
    public void selectJoinMenus(){
        MenuModelPageRequest pageRequest = new MenuModelPageRequest();
        pageRequest.setType("ADMIN");
        List<Menu> menus = menuMapper.selectJoinMenus(pageRequest);

        menus.forEach(System.out::println);

    }

    @Test
    public void getById(){
        Menu menu = this.menuService.getById(1);
        System.out.println(JSON.toJSONString(menu));
        Assert.assertNotNull(menu);
    }

    @Test
    public void list(){
        List<Menu> menus = this.menuService.list();
        menus.forEach(System.out::println);
    }

    @Test
    public void save(){
        Menu menu = new Menu();
        for(int i=0;i<100;i++){
            this.menuService.save(menu);
        }
    }

    @Test
    public void removeById(){
        boolean ret = this.menuService.removeById(1L);
        Assert.assertEquals(true,ret);
    }

    @Test
    public void saveOrUpdate(){
        Menu menu = this.menuService.getById(1);
        boolean ret = this.menuService.saveOrUpdate(menu);
        Assert.assertEquals(true,ret);
    }

    @Test
    public void page(){
        Integer currentPage = 1;
        Integer pageSize = 20;

        QueryWrapper<Menu> queryWrapper = new QueryWrapper<>();
        IPage<Menu> iPage = new Page<>(currentPage,pageSize);
        IPage<Menu> page = this.menuService.page(iPage,queryWrapper);

    }

}
